﻿using System;
using fastCSharp;

namespace diantou.web
{
    ///// <summary>
    ///// 用户权限视图
    ///// </summary>
    //static class permissionView
    //{
    //    /// <summary>
    //    /// 非安全连接重定向域名
    //    /// </summary>
    //    internal static pointer.size LocationDomain;

    //    unsafe static permissionView()
    //    {
    //        string locationDomain = diantou.dataModel.path.domain.Default.HttpDomain;
    //        fixed (char* domainFixed = locationDomain)
    //        {
    //            LocationDomain.Data = unmanaged.Get(LocationDomain.Size = locationDomain.Length, false).Data;
    //            fastCSharp.unsafer.String.WriteBytes(domainFixed, locationDomain.Length, LocationDomain.Byte);
    //        }
    //    }
    //}
    /// <summary>
    /// 用户权限视图
    /// </summary>
    /// <typeparam name="viewType"></typeparam>
    abstract class permissionView<viewType> : currentUserView<viewType>
        where viewType : permissionView<viewType>
    {
        /// <summary>
        /// 未审核竞赛数量
        /// </summary>
        protected int newExternalContestCount
        {
            get
            {
                if (currentUser.Permission == dataModel.user.permission.Admin)
                {
                    return diantou.dataAccess.tcpCall.contest.newExternalContestCount;
                }
                return 0;
            }
        }
        /// <summary>
        /// 未审核企业数量
        /// </summary>
        protected int newEnterpriseCount
        {
            get
            {
                if (currentUser.Permission == dataModel.user.permission.Admin)
                {
                    return diantou.dataAccess.tcpCall.user.newEnterpriseCount;
                }
                return 0;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected unsafe override bool loadView()
        {
            //if (!requestHeader.IsSsl && diantou.dataModel.path.domain.Default.TestCharCode == 0)
            //{
            //    subArray<byte> uri = requestHeader.Uri;
            //    fixed (byte* uriFixed = uri.UnsafeArray)
            //    {
            //        byte* uriStart = uriFixed + uri.StartIndex;
            //        int length = uri.Count;
            //        if (*uriStart == '/' && length != 0)
            //        {
            //            --length;
            //            ++uriStart;
            //        }
            //        pointer.size locationDomain = permissionView.LocationDomain;
            //        byte[] newUri = new byte[locationDomain.Size + length];
            //        fixed (byte* newUriFixed = newUri)
            //        {
            //            fastCSharp.unsafer.memory.UnsafeSimpleCopy(locationDomain.Byte, newUriFixed, locationDomain.Size);
            //            fastCSharp.unsafer.memory.UnsafeSimpleCopy(uriStart, newUriFixed + locationDomain.Size, length);
            //        }
            //        location(newUri, false);
            //        return false;
            //    }
            //}
            if (base.loadView())
            {
                if (currentUser.Permission != 0) return true;
                AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = currentUser.Path.NewFocus });
            }
            return false;
        }
    }
}
